package r21310.chap06.d1118;

import java.util.*;

class TreeSet1 {
    static List<student> list=new ArrayList<>();
    public static void main(String[] args) {
        student stu1=new student("刘备",90,1);
        student stu2=new student("哈哈",88,2);
        student stu3=new student("呵呵",85,3);
        student stu4=new student("张三",54,4);
        student stu5=new student("李四",88,5);
        student stu6=new student("王五",55,6);
        Collections.addAll(list,stu1,stu2,stu3,stu4,stu5,stu6);
        TreeSet<student> set=new TreeSet<>(new Comparator<student>() {
            @Override
            public int compare( student o1, student o2) {
                return Double.compare(o1.getChengji(), o2.getChengji());
            }
        });
        set.add(stu1);
        set.add(stu2);
        set.add(stu3);
        set.add(stu4);
        set.add(stu5);
        set.add(stu6);
        System.out.println(set.first());
        System.out.println(set.last());
        SortedSet<student> set1=set.subSet(new student("aa",80,1),new student("aa",90,2));
        System.out.println("成绩在80到90的学生信息："+set1);
        System.out.println("平均成绩为："+getAry1(list));

    }
    public static double getAry1(List<student> list) {
        double sum=0;
        Iterator<student> it=list.listIterator();
        while (it.hasNext()){
            student stu=it.next();
            sum+=stu.getChengji();
        }
        return sum/list.size();
    }

}
